<!DOCTYPE html>
<html lang="zh-CN">





<head>
  <meta charset="UTF-8">
  <link rel="apple-touch-icon" sizes="76x76" href="/img/icon-mouse.ico">
  <link rel="icon" type="image/png" href="/img/icon-mouse.ico">
  <meta name="viewport"
        content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, shrink-to-fit=no">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  
  <meta name="theme-color" content="#024e68">
  <meta name="description" content="">
  <meta name="author" content="织墨">
  <meta name="keywords" content="">
  <title>xml解析和sql连表 - 织墨</title>

  <link  rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/4.4.1/css/bootstrap.min.css" />


  <link  rel="stylesheet" href="https://cdn.staticfile.org/github-markdown-css/4.0.0/github-markdown.min.css" />
  <link  rel="stylesheet" href="/lib/hint/hint.min.css" />

  
    <link  rel="stylesheet" href="https://cdn.staticfile.org/highlight.js/10.0.0/styles/github-gist.min.css" />
  

  


<!-- 主题依赖的图标库，不要自行修改 -->

<link rel="stylesheet" href="//at.alicdn.com/t/font_1749284_yg9cfy8wd6.css">



<link rel="stylesheet" href="//at.alicdn.com/t/font_1736178_pjno9b9zyxs.css">


<link  rel="stylesheet" href="/css/main.css" />

<!-- 自定义样式保持在最底部 -->


  <script  src="/js/utils.js" ></script>
<meta name="generator" content="Hexo 5.0.0"></head>


<body>
  <header style="height: 70vh;">
    <nav id="navbar" class="navbar fixed-top  navbar-expand-lg navbar-dark scrolling-navbar">
  <div class="container">
    <a class="navbar-brand"
       href="/">&nbsp;<strong>织墨</strong>&nbsp;</a>

    <button id="navbar-toggler-btn" class="navbar-toggler" type="button" data-toggle="collapse"
            data-target="#navbarSupportedContent"
            aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
      <div class="animated-icon"><span></span><span></span><span></span></div>
    </button>

    <!-- Collapsible content -->
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
      <ul class="navbar-nav ml-auto text-center">
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/">
                <i class="iconfont icon-home-fill"></i>
                首页
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/archives/">
                <i class="iconfont icon-archive-fill"></i>
                归档
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/categories/">
                <i class="iconfont icon-category-fill"></i>
                分类
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/tags/">
                <i class="iconfont icon-tags-fill"></i>
                标签
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/about/">
                <i class="iconfont icon-user-fill"></i>
                关于
              </a>
            </li>
          
        
        
          <li class="nav-item" id="search-btn">
            <a class="nav-link" data-toggle="modal" data-target="#modalSearch">&nbsp;&nbsp;<i
                class="iconfont icon-search"></i>&nbsp;&nbsp;</a>
          </li>
        
      </ul>
    </div>
  </div>
</nav>

    <div class="view intro-2" id="background" parallax=true
         style="background: url('/img/bg2s.jpg') no-repeat center center;
           background-size: cover;">
      <div class="full-bg-img">
        <div class="mask flex-center" style="background-color: rgba(0, 0, 0, 0.3)">
          <div class="container text-center white-text fadeInUp">
            <span class="h2" id="subtitle">
              
            </span>

            
              
  <div class="mt-3 post-meta">
    <i class="iconfont icon-date-fill" aria-hidden="true"></i>
    <time datetime="2021-01-19 08:30">
      2021年1月19日 早上
    </time>
  </div>


<div class="mt-1">
  
    
    <span class="post-meta mr-2">
      <i class="iconfont icon-chart"></i>
      424 字
    </span>
  

  
    
    <span class="post-meta mr-2">
      <i class="iconfont icon-clock-fill"></i>
      
      
      7
       分钟
    </span>
  

  
  
    
      <!-- 不蒜子统计文章PV -->
      <span id="busuanzi_container_page_pv" style="display: none">
        <i class="iconfont icon-eye" aria-hidden="true"></i>
        <span id="busuanzi_value_page_pv"></span> 次
      </span>
    
  
</div>

            
          </div>

          
        </div>
      </div>
    </div>
  </header>

  <main>
    
      

<div class="container-fluid">
  <div class="row">
    <div class="d-none d-lg-block col-lg-2"></div>
    <div class="col-lg-8 nopadding-md">
      <div class="container nopadding-md" id="board-ctn">
        <div class="py-5" id="board">
          <div class="post-content mx-auto" id="post">
            
            <article class="markdown-body">
              <h1 id="在java中使用sax解析xml文件"><a href="#在java中使用sax解析xml文件" class="headerlink" title="在java中使用sax解析xml文件"></a>在java中使用sax解析xml文件</h1><p>引用的命名空间</p>
<pre><code class="hljs css"><span class="hljs-selector-tag">import</span> <span class="hljs-selector-tag">org</span><span class="hljs-selector-class">.dom4j</span><span class="hljs-selector-class">.Document</span>;
<span class="hljs-selector-tag">import</span> <span class="hljs-selector-tag">org</span><span class="hljs-selector-class">.dom4j</span><span class="hljs-selector-class">.DocumentFactory</span>;
<span class="hljs-selector-tag">import</span> <span class="hljs-selector-tag">org</span><span class="hljs-selector-class">.dom4j</span><span class="hljs-selector-class">.Element</span>;
<span class="hljs-selector-tag">import</span> <span class="hljs-selector-tag">org</span><span class="hljs-selector-class">.dom4j</span><span class="hljs-selector-class">.io</span><span class="hljs-selector-class">.SAXReader</span>;</code></pre>


<pre><code class="hljs java">SAXReader saxReader = <span class="hljs-keyword">new</span> SAXReader();
Document document = saxReader.read(wrappedStream);
Element infos = document.getRootElement();
<span class="hljs-keyword">for</span>(Iterator it = infos.elementIterator(); it.hasNext();)&#123;
    col++;
    <span class="hljs-comment">//第一层循环取值</span>
    Element info = (Element) it.next();
    <span class="hljs-comment">//取数据</span>
    String combstrategytype=info.element(<span class="hljs-string">&quot;name&quot;</span>).getTextTrim();
    String combname=info.element(<span class="hljs-string">&quot;gender&quot;</span>).getTextTrim();
    String combsplitday=info.element(<span class="hljs-string">&quot;age&quot;</span>).getTextTrim();

    Element telephonelist= strategy.element(<span class="hljs-string">&quot;telephonelist&quot;</span>);
    <span class="hljs-comment">//第二层循环取值</span>
    <span class="hljs-keyword">for</span>(Iterator itc = telephonelist.elementIterator(); itc.hasNext();)&#123;
        Element childUnit=(Element)itc.next();
        String remark=childUnit.element(<span class="hljs-string">&quot;remark&quot;</span>).getTextTrim();
        String number=childUnit.element(<span class="hljs-string">&quot;number&quot;</span>).getTextTrim(); 
    &#125;
&#125;
</code></pre>

<p>xml文件</p>
<pre><code class="hljs xml"><span class="hljs-tag">&lt;<span class="hljs-name">infos</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">info</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">name</span>&gt;</span>小明<span class="hljs-tag">&lt;/<span class="hljs-name">name</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">gender</span>&gt;</span>男<span class="hljs-tag">&lt;/<span class="hljs-name">gender</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">age</span>&gt;</span>28<span class="hljs-tag">&lt;/<span class="hljs-name">age</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">telephonelist</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">tel</span>&gt;</span>
                <span class="hljs-tag">&lt;<span class="hljs-name">remark</span>&gt;</span>公司<span class="hljs-tag">&lt;/<span class="hljs-name">remark</span>&gt;</span>
                <span class="hljs-tag">&lt;<span class="hljs-name">number</span>&gt;</span>123321456654<span class="hljs-tag">&lt;/<span class="hljs-name">number</span>&gt;</span>
            <span class="hljs-tag">&lt;/<span class="hljs-name">tel</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">tel</span>&gt;</span>
                <span class="hljs-tag">&lt;<span class="hljs-name">remark</span>&gt;</span>家<span class="hljs-tag">&lt;/<span class="hljs-name">remark</span>&gt;</span>
                <span class="hljs-tag">&lt;<span class="hljs-name">number</span>&gt;</span>08886666<span class="hljs-tag">&lt;/<span class="hljs-name">number</span>&gt;</span>
            <span class="hljs-tag">&lt;/<span class="hljs-name">tel</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">telephonelist</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">info</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">info</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">name</span>&gt;</span>小芳<span class="hljs-tag">&lt;/<span class="hljs-name">name</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">gender</span>&gt;</span>女<span class="hljs-tag">&lt;/<span class="hljs-name">gender</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">age</span>&gt;</span>22<span class="hljs-tag">&lt;/<span class="hljs-name">age</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">telephonelist</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">tel</span>&gt;</span>
                <span class="hljs-tag">&lt;<span class="hljs-name">remark</span>&gt;</span>公司<span class="hljs-tag">&lt;/<span class="hljs-name">remark</span>&gt;</span>
                <span class="hljs-tag">&lt;<span class="hljs-name">number</span>&gt;</span>19564897456<span class="hljs-tag">&lt;/<span class="hljs-name">number</span>&gt;</span>
            <span class="hljs-tag">&lt;/<span class="hljs-name">tel</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">tel</span>&gt;</span>
                <span class="hljs-tag">&lt;<span class="hljs-name">remark</span>&gt;</span>家<span class="hljs-tag">&lt;/<span class="hljs-name">remark</span>&gt;</span>
                <span class="hljs-tag">&lt;<span class="hljs-name">number</span>&gt;</span>06668888<span class="hljs-tag">&lt;/<span class="hljs-name">number</span>&gt;</span>
            <span class="hljs-tag">&lt;/<span class="hljs-name">tel</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">telephonelist</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">info</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">infos</span>&gt;</span></code></pre>

<h1 id="sql语句多条件查询"><a href="#sql语句多条件查询" class="headerlink" title="sql语句多条件查询"></a>sql语句多条件查询</h1><pre><code class="hljs sql"><span class="hljs-keyword">select</span>
<span class="hljs-keyword">CAST</span>(ipt.a <span class="hljs-keyword">as</span> <span class="hljs-built_in">FLOAT</span>)+<span class="hljs-keyword">CAST</span>(ipt.b <span class="hljs-keyword">as</span> <span class="hljs-built_in">FLOAT</span>) <span class="hljs-keyword">as</span> <span class="hljs-string">&quot;ab&quot;</span>,
<span class="hljs-keyword">case</span> <span class="hljs-keyword">when</span> seas.days <span class="hljs-keyword">is</span> <span class="hljs-literal">null</span> <span class="hljs-keyword">then</span> seas_all.days <span class="hljs-keyword">else</span> seas.days <span class="hljs-keyword">end</span> <span class="hljs-keyword">as</span> <span class="hljs-string">&quot;days&quot;</span>
<span class="hljs-keyword">from</span> <span class="hljs-keyword">position</span> ipt
<span class="hljs-keyword">left</span> <span class="hljs-keyword">join</span> (<span class="hljs-keyword">select</span> <span class="hljs-keyword">sys</span>,inv,exc,sto,<span class="hljs-keyword">days</span> <span class="hljs-keyword">from</span> tbseas) seas_all
<span class="hljs-keyword">on</span> <span class="hljs-keyword">trim</span>(seas_all.sys)=<span class="hljs-keyword">trim</span>(ipt.sys)
<span class="hljs-keyword">and</span> <span class="hljs-keyword">trim</span>(seas_all.inv)=<span class="hljs-keyword">trim</span>(ipt.inv)
<span class="hljs-keyword">and</span> <span class="hljs-keyword">trim</span>(seas_all.exc)=<span class="hljs-keyword">trim</span>(ipt.exc)
<span class="hljs-keyword">and</span> seas_all.sto=<span class="hljs-string">&#x27;*&#x27;</span>
<span class="hljs-keyword">left</span> <span class="hljs-keyword">join</span> (<span class="hljs-keyword">select</span> <span class="hljs-keyword">sys</span>,inv,exc,sto,<span class="hljs-keyword">days</span> <span class="hljs-keyword">from</span> tbseas) seas
<span class="hljs-keyword">on</span> <span class="hljs-keyword">trim</span>(seas_all.sys)=<span class="hljs-keyword">trim</span>(ipt.sys)
<span class="hljs-keyword">and</span> <span class="hljs-keyword">trim</span>(seas_all.inv)=<span class="hljs-keyword">trim</span>(ipt.inv)
<span class="hljs-keyword">and</span> <span class="hljs-keyword">trim</span>(seas_all.exc)=<span class="hljs-keyword">trim</span>(ipt.exc)
<span class="hljs-keyword">and</span> <span class="hljs-keyword">trim</span>(seas.sto)=<span class="hljs-keyword">trim</span>(ipt.sto)
<span class="hljs-keyword">and</span> seas.sto!=<span class="hljs-string">&#x27;*&#x27;</span>
<span class="hljs-keyword">where</span> <span class="hljs-number">1</span> = <span class="hljs-number">1</span></code></pre>



            </article>
            <hr>
            <div>
              <div class="post-metas mb-3">
                
                  <div class="post-meta mr-3">
                    <i class="iconfont icon-category"></i>
                    
                      <a class="hover-with-bg" href="/categories/%E6%95%B0%E6%8D%AE%E5%BA%93/">数据库</a>
                    
                      <a class="hover-with-bg" href="/categories/SQL/">SQL</a>
                    
                      <a class="hover-with-bg" href="/categories/Java/">Java</a>
                    
                  </div>
                
                
                  <div class="post-meta">
                    <i class="iconfont icon-tags"></i>
                    
                      <a class="hover-with-bg" href="/tags/%E6%95%B0%E6%8D%AE%E5%BA%93/">数据库</a>
                    
                      <a class="hover-with-bg" href="/tags/SQL/">SQL</a>
                    
                      <a class="hover-with-bg" href="/tags/Java/">Java</a>
                    
                  </div>
                
              </div>
              
                <p class="note note-warning">本博客所有文章除特别声明外，均采用 <a target="_blank" href="https://creativecommons.org/licenses/by-sa/4.0/deed.zh" rel="nofollow noopener noopener">CC BY-SA 4.0 协议</a> ，转载请注明出处！</p>
              
              
                <div class="post-prevnext row">
                  <div class="post-prev col-6">
                    
                    
                      <a href="/2021/01/25/JS%E8%BD%AC%E6%8D%A2%E6%97%A5%E6%9C%9F%E6%A0%BC%E5%BC%8F/">
                        <i class="iconfont icon-arrowleft"></i>
                        <span class="hidden-mobile">JS转换日期格式</span>
                        <span class="visible-mobile">上一篇</span>
                      </a>
                    
                  </div>
                  <div class="post-next col-6">
                    
                    
                  </div>
                </div>
              
            </div>

            
          </div>
        </div>
      </div>
    </div>
    
      <div class="d-none d-lg-block col-lg-2 toc-container" id="toc-ctn">
        <div id="toc">
  <p class="toc-header"><i class="iconfont icon-list"></i>&nbsp;目录</p>
  <div id="tocbot"></div>
</div>

      </div>
    
  </div>
</div>

<!-- Custom -->


    
  </main>

  
    <a id="scroll-top-button" href="#" role="button">
      <i class="iconfont icon-arrowup" aria-hidden="true"></i>
    </a>
  

  
    <div class="modal fade" id="modalSearch" tabindex="-1" role="dialog" aria-labelledby="ModalLabel"
     aria-hidden="true">
  <div class="modal-dialog modal-dialog-scrollable modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header text-center">
        <h4 class="modal-title w-100 font-weight-bold">搜索</h4>
        <button type="button" id="local-search-close" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body mx-3">
        <div class="md-form mb-5">
          <input type="text" id="local-search-input" class="form-control validate">
          <label data-error="x" data-success="v"
                 for="local-search-input">关键词</label>
        </div>
        <div class="list-group" id="local-search-result"></div>
      </div>
    </div>
  </div>
</div>
  

  

  

  <footer class="mt-5">
  <div class="text-center py-3">
    <div>
      <a href="https://hexo.io" target="_blank" rel="nofollow noopener"><span>Hexo</span></a>
      <i class="iconfont icon-love"></i>
      <a href="https://github.com/fluid-dev/hexo-theme-fluid" target="_blank" rel="nofollow noopener">
        <span>Fluid</span></a>
    </div>
    
  <div class="statistics">
    
    

    
      
        <!-- 不蒜子统计PV -->
        <span id="busuanzi_container_site_pv" style="display: none">
            总访问量 
            <span id="busuanzi_value_site_pv"></span>
             次
          </span>
      
      
    
  </div>


    

    
  </div>
</footer>

<!-- SCRIPTS -->
<script  src="https://cdn.staticfile.org/jquery/3.4.1/jquery.min.js" ></script>
<script  src="https://cdn.staticfile.org/twitter-bootstrap/4.4.1/js/bootstrap.min.js" ></script>
<script  src="/js/debouncer.js" ></script>
<script  src="/js/main.js" ></script>

<!-- Plugins -->


  
    <script  src="/js/lazyload.js" ></script>
  



  <script defer src="https://cdn.staticfile.org/clipboard.js/2.0.6/clipboard.min.js" ></script>
  <script  src="/js/clipboard-use.js" ></script>



  <script defer src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js" ></script>





  <script  src="https://cdn.staticfile.org/tocbot/4.11.1/tocbot.min.js" ></script>
  <script>
    $(document).ready(function () {
      var boardCtn = $('#board-ctn');
      var boardTop = boardCtn.offset().top;

      tocbot.init({
        tocSelector: '#tocbot',
        contentSelector: 'article.markdown-body',
        headingSelector: 'h1,h2,h3,h4,h5,h6',
        linkClass: 'tocbot-link',
        activeLinkClass: 'tocbot-active-link',
        listClass: 'tocbot-list',
        isCollapsedClass: 'tocbot-is-collapsed',
        collapsibleClass: 'tocbot-is-collapsible',
        collapseDepth: 0,
        scrollSmooth: true,
        headingsOffset: -boardTop
      });
      if ($('.toc-list-item').length > 0) {
        $('#toc').css('visibility', 'visible');
      }
    });
  </script>



  <script  src="https://cdn.staticfile.org/typed.js/2.0.11/typed.min.js" ></script>
  <script>
    var typed = new Typed('#subtitle', {
      strings: [
        '  ',
        "xml解析和sql连表&nbsp;",
      ],
      cursorChar: "|",
      typeSpeed: 60,
      loop: false,
    });
    typed.stop();
    $(document).ready(function () {
      $(".typed-cursor").addClass("h2");
      typed.start();
    });
  </script>



  <script  src="https://cdn.staticfile.org/anchor-js/4.2.2/anchor.min.js" ></script>
  <script>
    anchors.options = {
      placement: "right",
      visible: "hover",
      
    };
    var el = "h1,h2,h3,h4,h5,h6".split(",");
    var res = [];
    for (item of el) {
      res.push(".markdown-body > " + item)
    }
    anchors.add(res.join(", "))
  </script>



  <script  src="/js/local-search.js" ></script>
  <script>
    var path = "/local-search.xml";
    var inputArea = document.querySelector("#local-search-input");
    inputArea.onclick = function () {
      searchFunc(path, 'local-search-input', 'local-search-result');
      this.onclick = null
    }
  </script>



  <script  src="https://cdn.staticfile.org/fancybox/3.5.7/jquery.fancybox.min.js" ></script>
  <link  rel="stylesheet" href="https://cdn.staticfile.org/fancybox/3.5.7/jquery.fancybox.min.css" />

  <script>
    $('#post img:not(.no-zoom img, img[no-zoom]), img[zoom]').each(
      function () {
        var element = document.createElement('a');
        $(element).attr('data-fancybox', 'images');
        $(element).attr('href', $(this).attr('src'));
        $(this).wrap(element);
      }
    );
  </script>







  
  
    <script>
      !function (e, t, a) {
        function r() {
          for (var e = 0; e < s.length; e++) s[e].alpha <= 0 ? (t.body.removeChild(s[e].el), s.splice(e, 1)) : (s[e].y--, s[e].scale += .004, s[e].alpha -= .013, s[e].el.style.cssText = "left:" + s[e].x + "px;top:" + s[e].y + "px;opacity:" + s[e].alpha + ";transform:scale(" + s[e].scale + "," + s[e].scale + ") rotate(45deg);background:" + s[e].color + ";z-index:99999");
          requestAnimationFrame(r)
        }

        function n() {
          var t = "function" == typeof e.onclick && e.onclick;
          e.onclick = function (e) {
            t && t(), o(e)
          }
        }

        function o(e) {
          var a = t.createElement("div");
          a.className = "heart", s.push({
            el: a,
            x: e.clientX - 5,
            y: e.clientY - 5,
            scale: 1,
            alpha: 1,
            color: c()
          }), t.body.appendChild(a)
        }

        function i(e) {
          var a = t.createElement("style");
          a.type = "text/css";
          try {
            a.appendChild(t.createTextNode(e))
          } catch (t) {
            a.styleSheet.cssText = e
          }
          t.getElementsByTagName("head")[0].appendChild(a)
        }

        function c() {
          return "rgb(" + ~~(255 * Math.random()) + "," + ~~(255 * Math.random()) + "," + ~~(255 * Math.random()) + ")"
        }

        var s = [];
        e.requestAnimationFrame = e.requestAnimationFrame || e.webkitRequestAnimationFrame || e.mozRequestAnimationFrame || e.oRequestAnimationFrame || e.msRequestAnimationFrame || function (e) {
          setTimeout(e, 1e3 / 60)
        }, i(".heart{width: 10px;height: 10px;position: fixed;background: #f00;transform: rotate(45deg);-webkit-transform: rotate(45deg);-moz-transform: rotate(45deg);}.heart:after,.heart:before{content: '';width: inherit;height: inherit;background: inherit;border-radius: 50%;-webkit-border-radius: 50%;-moz-border-radius: 50%;position: fixed;}.heart:after{top: -5px;}.heart:before{left: -5px;}"), n(), r()
      }(window, document);
    </script>
  














</body>
</html>
